<title>人员信息管理</title>
<!-- /section:settings.box -->
<div class="row personnel_list">
	<div class="col-xs-12">
		<div class="ad_so">
			<select class="chosen-select" id="hx_sex">
				<option value="">性别</option>
				<option value="1">男</option>
				<option value="2">女</option>
			</select> <input type="text" id="hx_name" class="input-large"
				placeholder="姓名">
				<input type="text" id="hx_company_name" class="input-large"
				placeholder="企业名称">
				<input type="text" id="hx_card_number" class="input-large"
				placeholder="身份证号">
			<button type="button" class="btn btn-info serach">
				<i class="glyphicon glyphicon-search"></i> 搜索
			</button>
		</div>
		<!--  <div class="tabbable tabbable2">
			<ul class="nav nav-tabs padding-12 tab-color-blue background-blue">
				<li class="active" name= "li_tab"  data-identity="1"><a
					href="javascript:;"> 全部 </a></li>
			</ul>
		</div>-->
		<div class="row">
			<div class="col-xs-12">
				<div>
					<table class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th>序号</th>
								<th>姓名</th>
								<th>企业名称</th>
								<th>性别</th>
								<th>身份证号</th>
								<th>职称等级</th>
								<th>专业</th>
								<th>学历</th>
								<th>职称登记</th>
								<th>职称批准文号</th>

								<th>操作</th>
							</tr>
						</thead>
						<tbody class="data" style="display: table-row-group;">

						</tbody>
					</table>
				</div>
			</div>
		</div>
		<!--分页-->
		<nav class="pull-right">
			<ul class="pagination">
				<li><a class="first" href="javascript:void(1);"
					aria-label="Previous"> 首页</a></li>
				<li><a class="prev" href="javascript:void(1);"><i
						class="ace-icon fa fa-angle-double-left"></i>上一页</a></li>
				<li><a class="next" href="javascript:void(1);">下一页<i
						class="ace-icon fa fa-angle-double-right"></i></a></li>
				<li><a class="last" href="javascript:void(1);" aria-label="Next">尾页</a>
				</li>
				<li><a class="go_page" href="javascript:void(1);">跳转到</a></li>
				<li><input type="text" style="width: 30px" class="go_num" value="1"></li>
				<li>页</li>
			</ul>
		</nav>
		<!-- TemplteHidden -->
		<table class="list-tpl hidden">
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>

				<td>
					<button type="button" class="btn btn-mini btn-success detail"
						data-identity="detail" title="查看详情">
						<i class="ace-icon glyphicon glyphicon-eye-open"> 详情</i>
					</button>
					<button type="button" class="btn btn-mini btn-info edit"
						data-identity="edit" title="编辑">
						<i class="ace-icon glyphicon glyphicon-edit"> 编辑</i>
					</button>
					<button type="button" class="btn btn-mini btn-danger delete"
						data-identity="del" title="删除">
						<i class="ace-icon glyphicon glyphicon-trash"> 删除</i>
					</button>
				</td>
			</tr>
		</table>
	</div>
</div>
<script type="text/javascript">
var scripts = [null, null];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	var $scope = $('.personnel_list');	
	function pageInit(page){
		$.getJSON(page.url,
		{
			page:page.pi
		},						
			function(ret)
			{
				if(ret.status==200)
				{
					var $data=$('.data',$scope);
					$data.hide();
					$data.empty();
					var data=ret.data;							
					pageObj.set_page_count_without_action(ret.page_count);
					$("li[name='li_tab'][class='active'][data-identity='-1']>a", $scope).text("全部（" + ret.tct + "）");

					//从数据库中调取列表中的数据
					for(var i in data)
					{
						var v=data[i];
						var id=v['index'];
						var $item=$('.list-tpl tr',$scope).clone();
						//$('td:eq(0)',$item).text(id);
						//var $all="15"
						//for($i=2;$i<=15;$i++){
						$('td:eq(0)', $item).attr('i', 'i-' + i).text(i);
						//}
						$('td:eq(1)',$item).text(v['name']);
						$('td:eq(2)',$item).text(v['company_name']);
						if(v['sex']=="1" ||v['sex']=="男")
						$('td:eq(3)',$item).text("男");
						else if(v['sex']=="2" ||v['sex']=="女")
							$('td:eq(3)',$item).text("女");
						$('td:eq(4)',$item).text(v['card_number']);
						$('td:eq(5)',$item).text(v['level']);
						$('td:eq(6)',$item).text(v['profession']);
						$('td:eq(7)',$item).text(v['educational_background']);
						$('td:eq(8)',$item).text(v['job_title']);
						$('td:eq(9)',$item).text(v['job_title_number']);
					
						$('td:eq(10) .detail',$item).attr('data-identity','detail-'+i);
						$('td:eq(10) .edit',$item).attr('data-identity','edit-'+i);
						$('td:eq(10) .add',$item).attr('data-add','edit-'+id);
						$('td:eq(10) .delete',$item).attr('data-identity','delete-'+id);	
													
						$data.append($item);
					}//对应字符的输入框位
					$data.show();
				}
			
				else {
					pageObj.set_page_count_without_action(1);
					message_box.show(ret.data,'error');
				}
			});
		}
	pageObj=new pagination({
		'url':'/enterprise/ajax_personnel_list?id=<?=$id?>',
		'page_count':9,
		'show_callback':function(page)
		{
			pageInit(page);
		}
	});

	$('.first',$scope).click(function(){
		pageObj.first_page();
		$('.go_num',$scope).val('1');
	});
	$('.prev',$scope).click(function(){
		pageObj.prev_page();
		$('.go_num',$scope).val(pageObj.get_page_index());
	});
	$('.next',$scope).click(function(){
		pageObj.next_page();
		$('.go_num',$scope).val(pageObj.get_page_index());
	});
	$('.last',$scope).click(function(){
		pageObj.last_page();
		$('.go_num',$scope).val(pageObj.get_page_index());
	});
	//跳转输入框
	$('.go_num',$scope).change(function(){
		var num=$(this).val();
		if(num>pageObj.get_page_count()){
			$(this).val(pageObj.get_page_count());
		}else if(num<1){
			$(this).val(1);
		}
	})
	$('#serach').click(function(){
		var url = '/enterprise/ajax_personnel_list'+create_where();
	    pageObj=new pagination({
			'url':url,
			'page_count':2,
			'show_callback':function(page)
			{										
			    pageInit(page);
			}
		});				
	});
	//跳转至指定页面
	$('.go_page',$scope).click(function()
	{
		var num=$('.go_num',$scope).val();
		pageObj.go_page(num);
		$('.go_num',$scope).val(pageObj.get_page_index());
	});		
	$scope.delegate('[data-identity="add"]','click',function() {
		var url = '/enterprise/personnelAdd?dialog=1';
		gDialog.fCreate({title:'企业人员信息-增加',url: url,width:600}).show();
	}).delegate('[data-identity^="detail"]','click',function(){
		var id = $(this).attr('data-identity').split('-')[1];
		var url='/enterprise/personnelDetail?id='+id;
		gDialog.fCreate({title:'企业人员信息-详情',url: url,width:600}).show();
	}).delegate('[data-identity^="edit"]','click',function(){
		var id = $(this).attr('data-identity').split('-')[1];
		var url='/enterprise/personnelEdit?id='+id;
		gDialog.fCreate({title:'企业人员信息-编辑',url: url,width:600}).show();
	}).delegate('[data-identity^="delete-"]', 'click', function() {
		var id = $(this).attr('data-identity').split('-')[1];
		var url = '/enterprise/ajax_person_delete';
		gDialog.fConfirm('删除企业信息,同时删除企业所有人员信息', '你确定执行这个操作么？', function(ret) {
			if (ret) {
				$.post(url, {
					id: id
				}, function(ret) {
					if (ret.status = 200) {
						message_box.show('删除成功', 'success');
						pageObj.cur_page();
					} else {
						message_box.show(ret.data, 'error');
					}
				}, 'json');
			}
		});
	})
	function create_where() {
		var name = $("#hx_name", $scope).val() || "";
		var sex = $("#hx_sex",$scope).val()||"";
		var company_name=$("#hx_company_name",$scope).val() || "";
		var card_number = $("#hx_card_number",$scope).val() || "";
		var tb = $("li[name='li_tab'][class='active']", $scope).attr("data-identity");
		
		var where = "?id=<?=$id?>+&name=" + name+"&sex=" + sex + "&company=" + company_name + "&card=" + card_number;
		return where;
	}
	$("li[name='li_tab']", $scope).click(function() {
		$("li[name='li_tab']").removeClass("active");
		$(this).addClass("active");
		url = '/enterprise/ajax_personnel_list' + create_where();
		pageObj = new pagination({
			'url': url,
			'page_count': 9,
			'show_callback': function(page) {
				pageInit(page);
			}
		});
	});
	$('.serach').click(function() {
		var url = '/enterprise/ajax_personnel_list' + create_where();
		pageObj = new pagination({
			'url': url,
			'page_count': 9,
			'show_callback': function(page) {
				pageInit(page);
			}
		});
	});
})
</script>
